﻿@model MessageTemplateModel
@using SDF.Core.Domain.Messages;
@using SDF.Services

@Html.ValidationSummary(false)
@Html.HiddenFor(model => model.Id)

<div class="content">
    <div class="form-horizontal">

        <div class="panel-group">
            <div class="panel panel-default">
                <div class="panel-body">
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.AllowedTokens)
                        </div>
                        <div class="col-md-9">
                            <a id="allowedTokensShowHide" href="javascript:toggleLoadedAllowedTokens();">@T("Admin.Common.Show")</a>
                            <div id="pnlAllowedTokens" style="display: none">
                                @Html.SDFDisplayFor(model => model.AllowedTokens)
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.Name)
                        </div>
                        <div class="col-md-9">
                            @Html.SDFDisplayFor(model => model.Name)
                            @Html.HiddenFor(model => model.Name)
                        </div>
                    </div>
                    <script type="text/javascript">
                    function toggleLoadedAllowedTokens() {
                        $('#pnlAllowedTokens').toggle();
                        if ($('#pnlAllowedTokens').css('display') == 'none') {
                            $('#allowedTokensShowHide').html('@T("Admin.Common.Show")');
                        }
                        else {
                            $('#allowedTokensShowHide').html('@T("Admin.Common.Hide")');
                        }
                    }
                    </script>

                    @(Html.LocalizedEditor<MessageTemplateModel, MessageTemplateLocalizedModel>("messagetemplate-localized",
                @<div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.Locales[item].Subject)
                        </div>
                        <div class="col-md-9">
                            @Html.SDFEditorFor(model => model.Locales[item].Subject)
                            @Html.ValidationMessageFor(model => model.Locales[item].Subject)
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.Locales[item].Body)
                        </div>
                        <div class="col-md-9">
                            @Html.EditorFor(model => model.Locales[item].Body, "RichEditor")
                            @Html.ValidationMessageFor(model => model.Locales[item].Body)
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.Locales[item].BccEmailAddresses)
                        </div>
                        <div class="col-md-9">
                            @Html.SDFEditorFor(model => model.Locales[item].BccEmailAddresses)
                            @Html.ValidationMessageFor(model => model.Locales[item].BccEmailAddresses)
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.Locales[item].EmailAccountId)
                        </div>
                        <div class="col-md-9">
                            @Html.SDFDropDownListFor(model => model.Locales[item].EmailAccountId, Model.Locales[item].AvailableEmailAccounts)
                            @Html.ValidationMessageFor(model => model.Locales[item].EmailAccountId)
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-3">
                            <div class="label-wrapper">
                                <label class="control-label">
                                    @T("Admin.ContentManagement.MessageTemplates.Test")
                                </label>
                            </div>
                        </div>
                        <div class="col-md-9">
                            <button type="button" class="btn btn-primary" onclick="setLocation('@(Url.Action("TestTemplate", new {id = Model.Id, languageId = Model.Locales[item].LanguageId}))')">@T("Admin.ContentManagement.MessageTemplates.Test")</button>
                        </div>
                    </div>
                    @Html.HiddenFor(model => model.Locales[item].LanguageId)
                </div>
    ,
                    @<div>
                        <div class="form-group">
                            <div class="col-md-3">
                                @Html.SDFLabelFor(model => model.Subject)
                            </div>
                            <div class="col-md-9">
                                @Html.SDFEditorFor(model => model.Subject)
                                @Html.ValidationMessageFor(model => model.Subject)
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-3">
                                @Html.SDFLabelFor(model => model.Body)
                            </div>
                            <div class="col-md-9">
                                @Html.EditorFor(model => model.Body, "RichEditor")
                                @Html.ValidationMessageFor(model => model.Body)
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-3">
                                @Html.SDFLabelFor(model => model.BccEmailAddresses)
                            </div>
                            <div class="col-md-9">
                                @Html.SDFEditorFor(model => model.BccEmailAddresses)
                                @Html.ValidationMessageFor(model => model.BccEmailAddresses)
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-3">
                                @Html.SDFLabelFor(model => model.EmailAccountId)
                            </div>
                            <div class="col-md-9">
                                @Html.SDFDropDownListFor(model => model.EmailAccountId, Model.AvailableEmailAccounts)
                                @Html.ValidationMessageFor(model => model.EmailAccountId)
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-3">
                                <div class="label-wrapper">
                                    <label class="control-label">@T("Admin.ContentManagement.MessageTemplates.Test")</label>
                                </div>
                            </div>
                            <div class="col-md-9">
                                <button type="button" class="btn btn-primary" onclick="setLocation('@(Url.Action("TestTemplate", new {id = Model.Id}))')">@T("Admin.ContentManagement.MessageTemplates.Test")</button>
                            </div>
                        </div>
                    </div>
    ))

                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.IsActive)
                        </div>
                        <div class="col-md-9">
                            @Html.SDFEditorFor(model => model.IsActive)
                            @Html.ValidationMessageFor(model => model.IsActive)
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.SendImmediately)
                        </div>
                        <div class="col-md-9">
                            @Html.SDFEditorFor(model => model.SendImmediately)
                            @Html.ValidationMessageFor(model => model.SendImmediately)
                        </div>
                    </div>
                    <div class="form-group" id="pnl-send-after">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.DelayBeforeSend)
                        </div>
                        <div class="col-md-9">
                            <div class="row">
                                <div class="col-md-3">
                                    @Html.SDFEditorFor(model => model.DelayBeforeSend)
                                    @Html.ValidationMessageFor(model => model.DelayBeforeSend)
                                </div>
                                <div class="col-md-3">
                                    @Html.SDFDropDownListFor(model => model.DelayPeriodId, ((MessageDelayPeriod)Model.DelayPeriodId).ToSelectList(), new { style = "max-width: 200px;" })
                                    @Html.ValidationMessageFor(model => model.DelayPeriodId)
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.AttachedDownloadId)
                        </div>
                        <div class="col-md-4">
                            @{
                                //Static file attachments do not support URLs yet
                                //A project owner have to upload a file
                                //we project a value into "ViewData" and then use it in the Download.cshtml file
                                ViewData["sdf.DownloadEditor.DisableUrl"] = true;
                            }
                            <div class="checkbox">
                                <label>
                                    @Html.SDFEditorFor(model => model.HasAttachedDownload)
                                    @T("Admin.ContentManagement.MessageTemplates.Fields.AttachedDownload.Exists")
                                </label>
                            </div>
                            <div id="pnlAttachedDownload">
                                @Html.SDFEditorFor(model => model.AttachedDownloadId)
                                @Html.ValidationMessageFor(model => model.AttachedDownloadId)
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-3">
                            @Html.SDFLabelFor(model => model.SelectedProjectIds)
                        </div>
                        <div class="col-md-9">
                            <div class="row">
                                <div class="col-md-4">
                                    @Html.EditorFor(model => model.SelectedProjectIds, new {SelectList = Model.AvailableProjects})
                                    <script>
                                        $(document).ready(function() {
                                            var projectsIdsInput = $('#@Html.FieldIdFor(model => model.SelectedProjectIds)').data("kendoMultiSelect");
                                            projectsIdsInput.setOptions({
                                                autoClose: false
                                            });

                                            @if (Model.AvailableProjects.Count == 0)
                                            {
                                                <text>
                                    projectsIdsInput.setOptions({
                                        enable: false,
                                        placeholder: 'No Projects available'
                                    });
                                    projectsIdsInput._placeholder();
                                    projectsIdsInput._enable();
                                    </text>
                                            }
                                        });
                                    </script>
                                </div>
                                <div class="col-md-8">
                                    @Html.Action("MultiprojectDisabledWarning", "Common")
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script type="text/javascript">
            $(document).ready(function () {
                $("#@Html.FieldIdFor(model => model.HasAttachedDownload)").change(toggleHasAttachedDownload);
                $("#@Html.FieldIdFor(model => model.SendImmediately)").click(sendImmediately);
                toggleHasAttachedDownload();
                sendImmediately();
            });

            function toggleHasAttachedDownload() {
                if ($('#@Html.FieldIdFor(model => model.HasAttachedDownload)').is(':checked')) {
                    $('#pnlAttachedDownload').show();
                }
                else {
                    $('#pnlAttachedDownload').hide();
                }
            }

            function sendImmediately() {
                if ($('#@Html.FieldIdFor(model => model.SendImmediately)').is(':checked'))
                    $('#pnl-send-after').hide();
                else
                    $('#pnl-send-after').show();
            }
        </script>
    </div>
</div>




